package com.lianbang.staff.dialog

import android.os.Bundle
import android.view.View
import cn.ubest.mvvmcore.base.BaseDialogFragment
import cn.ubest.mvvmcore.utils.DoubleClickHelper
import cn.ubest.mvvmcore.utils.ResourcesUtils
import cn.ubest.mvvmcore.utils.TimeUtils
import cn.ubest.mvvmcore.utils.ToastUtils
import com.lianbang.staff.R
import com.lianbang.staff.bean.ShopOrderDetailBean
import com.lianbang.staff.databinding.DialogShipConfirmBinding
import com.lianbang.staff.model.OrderModel
import com.lianbang.staff.module.main.OrderDetailActivity
import kotlinx.android.synthetic.main.dialog_ship_confirm.*

/**
 * Created by maoqi on 2021/1/13.
 */
class ShipConfirmDialog : BaseDialogFragment<DialogShipConfirmBinding>() {

    private var mBean: ShopOrderDetailBean? = null

    private val mModel by lazy {
        OrderModel()
    }

    companion object {
        fun newInstance(
            bean: ShopOrderDetailBean
        ): ShipConfirmDialog {
            val args = Bundle()
            val fragment = ShipConfirmDialog()
            fragment.arguments = args
            fragment.mBean = bean
            return fragment
        }
    }

    override fun initLayout(): Int {
        return R.layout.dialog_ship_confirm
    }

    override fun initData(arguments: Bundle?) {
    }

    override fun initView(view: View) {
        setWidth(ResourcesUtils.getDimens(R.dimen.dp_335))
        mBean?.apply {
            tv_order_number.text = "订单编号：${order_id}"
            tv_date.text = TimeUtils.formatTime(add_time * 1000, "yyyy/MM/dd")
            tv_category_number.text = "$cart_num"
            tv_number.text = "$total_num"
            tv_total_money.text = total_price
            tv_code.text = total_price
        }


        btn_submit.setOnClickListener(object : DoubleClickHelper.OnClickListener() {
            override fun onClicked(view: View?) {
                val input = et_input.text.toString()
                if (input.trim().isEmpty()) {
                    ToastUtils.toast("验证码不能为空")
                    return
                }
                if (input.trim() != tv_code.text) {
                    ToastUtils.toast("验证码错误")
                    return
                }
                if (activity is OrderDetailActivity) {
                    (activity as OrderDetailActivity).orderStateChanged()
                }
                finishSelf()
            }

        })
    }

    override fun loadData() {
    }

}